﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Markup;
using System.Windows.Controls.Primitives;

namespace BizControl.Presentation.Infrastructure.Controls
{
  [ContentProperty("TipContent")]
  public partial class InfoToolTipControl : UserControl
  {
    public InfoToolTipControl()
    {
      InitializeComponent();

      MouseEnter += new MouseEventHandler(InfoToolTipControl_MouseEnter);
      MouseLeave += new MouseEventHandler(InfoToolTipControl_MouseLeave);
    }

    void InfoToolTipControl_MouseLeave(object sender, MouseEventArgs e)
    {
      (popup.Child as ContentControl).Content = null;
      popup.IsOpen = false;
    }

    void InfoToolTipControl_MouseEnter(object sender, MouseEventArgs e)
    {
      if (!popup.IsOpen)
      {
        (popup.Child as ContentControl).Content = (UIElement)TipContent;
        popup.IsOpen = true;
      }
    }

    public static readonly DependencyProperty TipContentProperty =
      DependencyProperty.Register("TipContent", typeof(object), typeof(InfoToolTipControl), new PropertyMetadata(null));
    
    public object TipContent
    {
      get
      {
        return GetValue(TipContentProperty);
      }
      set
      {
        SetValue(TipContentProperty, value);
      }
    }

  }
}
